Skip to content

Explicit parameter binding - #1018

Closed
KathleenDollard wants to merge 23 commits into
dotnet:mainfrom
KathleenDollard:explicit-binding-4
Closed

Explicit parameter binding#1018
KathleenDollard wants to merge 23 commits into
dotnet:mainfrom
KathleenDollard:explicit-binding-4

Conversation

@KathleenDollard

Copy link
Copy Markdown
Contributor

Significant updates to binding so method binding and model binding use the same logic and same code paths.

Draft due to rebase issues.

@KathleenDollard KathleenDollard changed the title Explicit binding 4 Explicit parameter binding Aug 9, 2020
Comment thread src/System.CommandLine.Tests/Binding/ModelBinderConstructorTests.cs Outdated
Comment thread src/System.CommandLine.Tests/Binding/ModelBinderConstructorTests.cs Outdated
Comment thread src/System.CommandLine.Tests/Binding/ModelBinderConstructorTests.cs Outdated
Comment thread src/System.CommandLine/Binding/BindingContext.cs Outdated
{
public class BoundValue
{
// ?? Why have an internal constructor on a public readonly class?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want people to create instances of this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not appear that BoundValue escape the context of System.CommandLine. I think we should deliberately consider the needs of any application models that need something other than to connect a ValueSource to a Option/Argument ahead of any evaluation. IOW, we may need this public in the future, but it does not appear that we need it public now.

This is probably part of a broader discussion of checking our public API surface.

Comment thread src/System.CommandLine/Binding/ServiceProviderValueSource.cs Outdated
{
public static class InvocationExtensions
{
public static void BindParameter(this ICommandHandler handler, ParameterInfo param, Option option)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't be necessary, correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is needed, although it might not be in the right place. That extension method drives the following syntax:

            handler.BindParameter(parameter, argument);
            command.Handler = handler;

The handler is managed as an ICommandHandler, so putting the method on the interface isn't sensible due to the ParameterInfo/PropertyInfo. Thus, an extension method seemed the right approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or were you just expecting to always do it on the argument and this is on the option?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think making ModelBindingCommandHandler public makes more sense than extending the interface but throwing if it's the wrong implementation.

@brettfo
brettfo changed the base branch from master to main August 19, 2020 19:52
@KathleenDollard

Copy link
Copy Markdown
Contributor Author

Closing in favor of non-draft one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants